package shovelsoft.btmetaparser.structs;

import java.util.LinkedList;
import java.util.List;

import shovelsoft.btmetaparser.tokens.IToken;

/***
 * Implements a branch node. May represent a Dictionary/List.
 * @author Chris Stones
 */
public class Node implements INode {

	private List<INode> children;
	private final INode parent;
	private final IToken token;
	
	/***
	 * Create a  Node
	 * @param token associate this leaf with the given token
	 * @param parent the parent of this mode
	 */
	public Node(IToken token, INode parent) {
		
		this.parent = parent;
		this.token  = token;
		children = new LinkedList<INode>();
	}
	
	/***
	 * Add a child to this node.
	 * @param child Child to add.
	 */
	@Override
	public void addChild(INode child) throws Exception {
		
		children.add( child );
	}

	/***
	 *  Get list of this nodes children
	 *  @return List of child nodes
	 */
	@Override
	public List<INode> getChildren() {

		return children;
	}

	/***
	 * Get this nodes parent ( null for root )
	 *  @return parent
	 */
	@Override
	public INode getParent() {

		return parent;
	}

	/***
	 *  Get the token associated with this node
	 *  @return associated token.
	 */
	@Override
	public IToken getToken() {
		
		return token;
	}
}
